<template>
	<view class="completed">
		<view>
			<view class="topItem">
				<view class="left">
					<image :src="data.httpUrl+'/app/file/viewFile?fileId='+item.storeLogo" mode="aspectFill"></image>
					{{item.storeName}}
				</view>
				<view class="right">
					售后成功
				</view>
			</view>
			<view>

			</view>
			<Item v-for="(item1,index1) in item.productDTOS" :key="index1" :item="item1" />
		</view>
		<view class="bot" >
			<text @tap.stop="contactMerchant(item)">联系商家</text>
			<text @tap.stop="handeCart(item)">加入购物车</text>
			<text @tap.stop="repurchase(item)">重新购买</text>
		</view>
	</view>
</template>

<script setup lang="ts">
	//已完成
	import Item from './item'
	import { reactive } from 'vue';
	import { orderToShoppingCar } from '@/utils/api/goods'
	const props = defineProps(['item'])
	const data = reactive<any>({
		httpUrl: getApp().globalData.baseUrl,
	})
	const contactMerchant = (item) => {
		const conversationID = `C2C${item.sellUserId}`;
		uni.navigateTo({ url: `/pages/TUIKit/components/TUIChat/index?conversationID=${conversationID}&userId=${item.sellUserId}&trendsId=${item.sonOrderNo}&areaType=order` });
	}
	const handeCart = (item) => {
		uni.showLoading({
			title: '加载中...',
			mask: true
		})
		orderToShoppingCar({ data: { sonOrderNo: item.sonOrderNo } }).then((res) => {
			if (res.code == 200) {
				uni.showToast({
					title: '购物车添加成功!',
					icon: 'none'
				})
			}
		})
	}
	const repurchase = (i) => {
		i.name = i.storeName;
		i.productDTOS.map((item1) => {
			item1.fileId = item1.mainPicture;
			item1.productName = item1.spuName;
			item1.price = (item1.price + '').indexOf('.') == -1 ? item1.price + '.00' : item1.price
		})
		i.list = i.productDTOS;
		uni.navigateTo({
			url: "/pages/confirmOrder/index"
		})
		setTimeout(() => {
			uni.$emit('confirmOrder', [i])
		}, 500)

	}
</script>

<style lang="scss">
	.completed {
		>.bot1 {
			display: flex;
			align-items: center;
			justify-content: space-between;
			font-size: 24rpx;
			color: #8C8C8C;
			margin-top: 25rpx;

			view {
				font-size: 24rpx;

				text {
					font-size: 36rpx;
					color: #6B64D3;
				}
			}
		}

		>.bot {
			margin-top: 33rpx;
			display: flex;
			align-items: flex-end;
			justify-content: flex-end;

			text {
				padding: 11rpx 24rpx;
				border-radius: 100rpx;
			}

			text:nth-of-type(1) {
				border: 2rpx solid #D9D9D9;
				margin-right: 16rpx;
			}

			text:nth-of-type(2) {
				color: #6B64D3;
				border: 2rpx solid #6B64D3;
				margin-right: 16rpx;
			}

			text:nth-of-type(3) {
				border: 2rpx solid #94bcff;
			}
		}

		.topItem {
			display: flex;
			align-items: center;
			justify-content: space-between;

			.left {
				display: flex;
				align-items: center;
				font-size: 32rpx;

				image {
					width: 48rpx;
					height: 48rpx;
					border-radius: 50%;
					margin-right: 16rpx;
				}

				text {
					padding: 5rpx 10rpx;
					border-radius: 100rpx;
					border: 2rpx solid #D9D9D9;
					margin-left: 10rpx;
				}
			}

			.right {
				color: #6AC922;
			}
		}
	}
</style>